package weaver.interfaces.jjy.duss.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/*
 *@Description: 年终奖上报（华润）流程：当总部审批节点，退回后，
 * ①根据年份、月份(推送)、人事范围编码，清空uf_nzjcfhz中的BMSBYJJ、BMSBJTJ，并将zt更新为0；
 * ②根据流程明细中的年份、月份、人员编码，去清空uf_nzjcfhr中的YJJ、JTJ；
 *@Author: Dusongsong
 *@Date: 2019/12/24
 */
public class WeaHRnzjHRhtAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {

        RecordSet rs = new RecordSet();
        RecordSet rs2 = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用: WeaHRnzjHRhtAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        String STATE = "0";
        String message = "";
        //更新汇总表
        rs.executeQuery("select * from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("select * from " + tablename + " where requestid=" + requestid);
        rs.next();
        String mainid = Util.null2String(rs.getString("id"));//外键
        String GJAHR = Util.null2String(rs.getString("GJAHR"));//年份
        String BMBM = Util.null2String(rs.getString("BMBM"));//部门编码
        String WERKS = Util.null2String(rs.getString("WERKS"));//人事范围编码
        if ("8004".equals(WERKS) || "8007".equals(WERKS) || "ZB01".equals(WERKS)) {
            //更新明细表
            rs2.execute("select * from " + tablename + "_dt1 where mainid='" + mainid + "' and  werks = '"+WERKS+"' and gjahr = '"+GJAHR+"' and bmbm = '"+BMBM+"'");
            while (rs2.next()){
                String updateSQL = "update uf_nzjcfhr set yjj='',jtj='' where werks='" + WERKS + "' and gjahr='" + GJAHR + "' and bmbm='" + BMBM + "' ";
                rs2.executeUpdate(updateSQL);
                baseBean.writeLog(updateSQL);
                baseBean.writeLog(message);
            }
            //更新汇总表
            String sql = "update uf_nzjcfhz set bmsbyjj='',bmsbjtj='',zt='" + STATE + "' where werks='" + WERKS + "' and gjahr='" + GJAHR + "' and bmbm='" + BMBM + "' ";
            rs.executeUpdate(sql);
            baseBean.writeLog(sql);
            return Action.SUCCESS;
        }else {
            //更新明细表
            rs2.execute("select * from " + tablename + "_dt1 where mainid='" + mainid + "' and  werks = '"+WERKS+"' and gjahr = '"+GJAHR+"'");
            while (rs2.next()){
                String updateSQL = "update uf_nzjcfhr set yjj='',jtj='' where werks='" + WERKS + "' and gjahr='" + GJAHR + "' ";
                rs2.executeUpdate(updateSQL);
                baseBean.writeLog(updateSQL);
                baseBean.writeLog(message);
            }
            //更新汇总表
            String sql = "update uf_nzjcfhz set bmsbyjj='',bmsbjtj='',zt='" + STATE + "' where werks='" + WERKS + "' and gjahr='" + GJAHR + "'";
            rs.executeUpdate(sql);
            baseBean.writeLog(sql);
            return Action.SUCCESS;
        }


    }

}



